package com.shang.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @ClassName UserProxy
 * @Description TODO
 * @Author Larry
 * @Date 2021/5/20 14:50
 * @Version 1.0
 */

@Component
@Aspect //生成代理对象
public class UserProxy {

    //前置通知
    @Before(value = "execution(* com.shang.aop.User.add(..))")
    public void before(){
        System.out.println("before.............");
    }

    @After(value = "execution(* com.shang.aop.User.add(..))")
    public void after(){
        System.out.println("after.............");
    }

    @AfterReturning(value = "execution(* com.shang.aop.User.add(..))")
    public void afterReturning(){
        System.out.println("afterReturning.............");
    }
    @AfterThrowing(value = "execution(* com.shang.aop.User.add(..))")
    public void afterThrowing(){
        System.out.println("afterThrowing.............");
    }
    @Around(value = "execution(* com.shang.aop.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint){
        System.out.println("around.............之前");
        try {
            proceedingJoinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("around.............之后");
    }
}
